<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>菜单</title>
    <link rel="stylesheet" href="assets/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body>
<div ng-app="menuApp" ng-controller="menuCtrl">
    <div class="col-md-6">
        <ui-tree key="menuTree" pid-name="pcode" url="system/menu/list" editable="true"></ui-tree>
    </div>
    <div class="col-md-6">
        <ui-form key="orgAdd" column="1">
            <div class="row">
                <input name="id" type="hidden" value="{{nodeData.id}}"/>
            </div>
            <ui-form-input name="code" label="菜单编码:" value="{{nodeData.code}}"></ui-form-input>
            <ui-form-input name="pCode" readonly="true" label="父编码:" value="{{nodeData.pcode}}" ></ui-form-input>
            <ui-form-input name="name" label="菜单名称:" value="{{nodeData.name}}"></ui-form-input>
            <ui-form-input name="url" label="菜单路径:" value="{{nodeData.url}}"></ui-form-input>
            <ui-form-select name="type" label="菜单类型:" value="{{nodeData.type}}">
                <option value="1">目录</option>
                <option value="2">菜单</option>
                <option value="3">功能</option>
            </ui-form-select>
            <ui-form-input name="sort" label="菜单排序:" value="{{nodeData.sort}}"></ui-form-input>
        </ui-form>
    </div>
    <script>
        angular.module('menuApp',['ui.tree','ui.form']);
        angular.module('menuApp').controller('menuCtrl', function($scope,eventHelper){
            var url="system/menu/add";
            $scope.editTree=function (treeId,node) {
                if(node.code==null){
                    toastr.error("根目录无法编辑")
                    return false;
                }
                $scope.nodeData=node;
                url="system/menu/update";
                $scope.$apply();
                eventHelper.downNotice($scope,'ngValueReset');
                return false;
            }
            $scope.addTree=function (treeId,node) {
                $scope.nodeData={pcode:node.code};
                url="system/menu/add";
                $scope.$apply();
                eventHelper.downNotice($scope,'ngValueReset');
                return false;
            }
            $scope.removeTree=function (treeId,node) {
                console.log(node);
                if(node.code==null){
                    toastr.error("根目录无法删除")
                    return false;
                }
                $.ajax({
                    url:"system/menu/del",
                    type:"post",
                    data:{id:node.id}
                }).done(function (result) {
                    if(result.code=='0000'){
                        $scope['menuTree']._queryData();
                        toastr.success("删除成功");
                    }else{
                        toastr.error(result.msg);
                    }
                }).fail(function (err) {

                });
                return false;
            }

            $scope.nodeData={};
            $scope.$on('ui.form.submit',function (event,param) {
                $.ajax({
                    url:url,
                    type:"post",
                    data:param
                }).done(function (result) {
                    if(result.code=='0000'){
                        $scope['menuTree']._queryData();
                        toastr.success("保存成功");
                    }else{
                        toastr.error(result.msg);
                    }
                }).fail(function (err) {

                });
            })
        });
    </script>
    <script type="text/javascript" src="assets/ztree/jquery.ztree.core.min.js"></script>
    <script type="text/javascript" src="assets/ztree/jquery.ztree.excheck.min.js"></script>
    <script type="text/javascript" src="assets/ztree/jquery.ztree.exedit.min.js"></script>
</div>
</body>
</html>